<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('enterprise_edit_user_account_page_title'));
$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css');

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.droppable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js')
    ;
?>
<style>
    .t_a_ui_helper_loading{
        padding-right: 100px;
    }
</style>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'enterprise_enterprise_list'); ?>"><?php echo $this->translator('enterprise_list_breadcump'); ?></a></span>
    <span><?php echo $this->translator('enterprise_edit_user_account_breadcump'); ?></span>
</div>

<div class="grid_12 t_a_bottom">
    <div class="grid_9 alpha"><?php echo $this->translator('enterprise_list_user_account_guide'); ?></div>
    <?php if(count($this->userAccount) <= 0):?>
    <?php if($this->allow('user-create')):?>
    <div id="add_html">
        <div class="grid_3 omega">
            <div class="t_a_right">
                <a href="javascript:void(0)" class="t_a_ui_button_link" id="createUser"><span><?php echo $this->translator('enterprise_add_user_account_breadcrump'); ?></span></a>
            </div>
        </div>
    </div>
    <?php endif;?>
    <?php endif;?>
</div>

<?php if(!$this->isAllowed):?>
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <?php echo $this->translator('enterprise_not_edit_basic_guide'); ?>
    </div>
</div>
<?php else:?>
<div class="grid_12 t_a_ui_data_list_header">
    <div class="grid_6 alpha"><?php echo $this->translator('enterprise_login_name'); ?></div>
    <div class="grid_4"><?php echo $this->translator('enterprise_role'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('enterprise_action'); ?></div>
</div>

<div class="grid_12 t_a_bottom" id="user">
    <div id="target_html">
    <?php if(count($this->userAccount) > 0):?>
        <?php foreach($this->userAccount as $row):?>
        <div id="userRow_<?php echo $row->user_id; ?>" class="clearfix t_a_ui_data_list_content">
            <div class="grid_6 alpha"><?php echo $row->user_name;?></div>
            <div class="grid_4"><?php echo $row->role_name;?></div>
            <div class="grid_2 omega">
                <div class="t_a_ui_helper_action">
                    <?php if($this->allow('edit','user','core')):?>
                    <a href="<?php echo $this->url(array('user_id' => $row->user_id), 'enterprise_user_account_edit'); ?>"><?php echo $this->translator('enterprise_edit_user_account'); ?></a>
                    <?php endif;?>
                </div>
            </div>
        </div>
        <?php endforeach;?>
    <?php endif;?>
    </div>
</div>
<?php endif;?>

<div id="messageDialog"></div>
<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {

    $('#createUser').click(function() {
        var self = this;
        $(self).html('').addClass('t_a_ui_helper_loading');
        $.ajaxq('user', {
            type: 'POST',
            url: "<?php echo $this->url(array(), 'enterprise_enterprise_user_account_create'); ?>",
            data: { id: '<?php echo $this->id;?>' },
            success: function(html) {
                $('#target_html').html(html);
                $('#add_html').html('');

                /**
                * View user account info
                */
                var user_info = $('#user_info').html();
                $('#messageDialog').html(user_info)
                        .dialog({
                            title: '<?php echo addslashes($this->translator('common_dialog_message')); ?>',
                            dialogClass: 't_a_ui_dialog',
                            width: 350,
                            height: 200,
                            resizable: true,
                            autoResize: true,
                            modal: true,
                            show: { effect: 'fade' },
                            open: function(event, ui) {
                                setTimeout(function() {
                                    $('#' + event.target.id).dialog('option', 'hide', 'fade').dialog('destroy');
                                }, 30000000);
                            }
                });

            }
        });
    });
});
</script>